package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ParkingWhite;
import com.ruoyi.service.IParkingWhiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 白名单
Controller
 * 
 * @author ruoyi
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/parking/white")
public class ParkingWhiteController extends BaseController
{
    @Autowired
    private IParkingWhiteService parkingWhiteService;

    /**
     * 查询白名单
列表
     */
    @PreAuthorize("@ss.hasPermi('parking:white:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkingWhite parkingWhite)
    {
        startPage();
        List<ParkingWhite> list = parkingWhiteService.selectParkingWhiteList(parkingWhite);
        return getDataTable(list);
    }

    /**
     * 导出白名单
列表
     */
    @PreAuthorize("@ss.hasPermi('parking:white:export')")
    @Log(title = "白名单 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkingWhite parkingWhite)
    {
        List<ParkingWhite> list = parkingWhiteService.selectParkingWhiteList(parkingWhite);
        ExcelUtil<ParkingWhite> util = new ExcelUtil<ParkingWhite>(ParkingWhite.class);
        util.exportExcel(response, list, "白名单 数据");
    }

    /**
     * 获取白名单
详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:white:query')")
    @GetMapping(value = "/{whiteId}")
    public AjaxResult getInfo(@PathVariable("whiteId") Long whiteId)
    {
        return success(parkingWhiteService.selectParkingWhiteByWhiteId(whiteId));
    }

    /**
     * 新增白名单

     */
    @PreAuthorize("@ss.hasPermi('parking:white:add')")
    @Log(title = "白名单 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkingWhite parkingWhite)
    {
        return toAjax(parkingWhiteService.insertParkingWhite(parkingWhite));
    }

    /**
     * 修改白名单

     */
    @PreAuthorize("@ss.hasPermi('parking:white:edit')")
    @Log(title = "白名单 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkingWhite parkingWhite)
    {
        return toAjax(parkingWhiteService.updateParkingWhite(parkingWhite));
    }

    /**
     * 删除白名单

     */
    @PreAuthorize("@ss.hasPermi('parking:white:remove')")
    @Log(title = "白名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{whiteIds}")
    public AjaxResult remove(@PathVariable Long[] whiteIds)
    {
//        return toAjax(parkingWhiteService.deleteParkingWhiteByWhiteIds(whiteIds));
        //只删除一个
        return toAjax(parkingWhiteService.deleteParkingWhiteByWhiteId(whiteIds[0]));
    }

    @Log(title = "白名单", businessType = BusinessType.UPDATE)
    @PutMapping("/resend/{whiteId}")
    public AjaxResult resend(@PathVariable Long whiteId){
        ParkingWhite parkingWhite = parkingWhiteService.selectParkingWhiteByWhiteId(whiteId);
        return toAjax(parkingWhiteService.sendRequest(parkingWhite));
    }

}
